# -*- encoding: utf-8 -*-
# Pyinstaller -w -i success.ico main.py
"""
@Modify Time          @Author      @Version    @Description
--------------      -----------    --------    ------------
2023/3/13 17:48     chuxiaodong      1.0           None
"""
import json
import shutil
import requests
import os
from webdriver_manager.core.utils import get_browser_version_from_os
from webdriver_manager.chrome import ChromeDriverManager


dir_path = os.path.dirname(os.path.abspath(__file__))
browserVersion = get_browser_version_from_os("google-chrome")
browserVersion = "LATEST_RELEASE_" + str(browserVersion.split(".")[0])
url = "https://registry.npmmirror.com/-/binary/chromedriver/"
resp = requests.get(url=url)
resp = json.loads(resp.text)
file_path = None
for i in resp:
    if i['name'] == browserVersion:
        url = i['url']
        resp = requests.get(url=url)
        resp = resp.text
        file_path = ChromeDriverManager(version=resp).install()
        break
shutil.copy(file_path, dir_path)
